package com.wy.projectssj.dao.impl;

import com.wy.projectssj.dao.UserRoleDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

/**
 * @Author: wy
 * @Date:2019/8/29 0:33
 */
@Repository
public class UserRoleDaoImpl implements UserRoleDao {
      @Autowired
       private JdbcTemplate jdbcTemplate;
    @Override
    public int deleteByIds(String[] ids) {
        int result=-1;
        String s="delete from users_role where 1=1 and userId in(";
        StringBuilder sql=new StringBuilder(s);
        for (int i = 0; i <ids.length ; i++) {
            if(i==ids.length-1){
                sql.append("?)");
            }else{
                sql.append("?,");
            }
        }
        try {
            result = jdbcTemplate.update(sql.toString(), ids);
        } catch (DataAccessException e) {
        }
        return result;
    }
}
